package TetrisFlash 
{
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	import TetrisFlash.GameLoadData.SoundManager;
	
	import starling.display.Sprite;
	import starling.core.Starling;
	
	import TetrisFlash.Screen.Screen;
	/**
	 * ...
	 * @author DANTRUONG
	 */
	public class Game extends Sprite 
	{
		public static const GAME_STATE_PLAY:int = 0;
		public static const GAME_STATE_PAUSE:int = 1;
		public static const GAME_STATE_ANIMATE:int = 2;
		
		//sound
		public var soundManager:SoundManager;
		//viewport of screen
		public var viewPort:Rectangle;
		//current screen
		protected var curScreen:Screen;
		//list screens to manager
		protected var listScreens:Dictionary;
		
		public var gameDeltaTime:Number;
		
		public function Game() 
		{
			super();
			listScreens = new Dictionary();
			viewPort = Starling.current.viewPort;
		}
		
		public function getCurScreen():Screen 
		{
			return curScreen;
		}
		
		//change screen by class of screen
		public function setScreen (value:Class):void {
			var screen:Screen;
			
			if (listScreens[getQualifiedClassName(value)] == null) {
				screen = new value(this);
				listScreens[getQualifiedClassName(value)] = screen;
			} else {
				screen = listScreens[getQualifiedClassName(value)];
			}
			
			if (curScreen) {
				//clear current screen
				curScreen.destroyScreen();
				removeChild(curScreen);
			}
			
			curScreen = screen;
			curScreen.initScreen();
			addChild(curScreen);
		}
		
		public function get screenWidth ():int {
			return viewPort.width;	
		}
		
		public function get screenHeight ():int {
			return viewPort.height;	
		}
		
		protected function updateGame (deltaTime:Number):void {
			gameDeltaTime = deltaTime;
		}
		
		protected function drawGame ():void {
		
		}
		
		protected function releaseGame ():void {
			
		}
	}

}